import * as request from "../../utils/request/user/personManage"

Page({
  data: {
    userAccount: '',
   
    userPassword: '',
    userRole: ''
  },

  onAccountInput(e) {
    this.setData({
      userAccount: e.detail.value
    });
  },
  onPasswordInput(e) {
    this.setData({
      userPassword: e.detail.value
    });
  },

  onRoleInput(e) {
    this.setData({
      userRole: e.detail.value
    });
  },

  async addUser() {
    const { userAccount,  userPassword, userRole } = this.data;

    if (!userAccount ||  !userPassword || !userRole) {
      wx.showToast({
        title: '请填写完整信息',
        icon: 'none'
      });
      return;
    }
    let res = await request.addUser(this.data)
    console.log(res)
    if(res.code === 0){
      wx.showToast({
        title: '用户添加成功',
        icon: 'success'
      });
     this.setData({
      userAccount: '',
      
      userPassword: '',
      userRole: ''
     })
    }else{
      wx.showToast({
        title: '添加失败',
        icon: 'none'
      });
    }
  }
});